from sched_web import *
from pprint import pformat
import re

@app.route("/selection/<semester>")
def page_selection(semester):
  "Course selection"
  return render_template("selection.html", semester=semester)

@app.route("/_reschedule/<semester>")
def page_schedule(semester):
  "re-scheduler"
  courses = request.args.getlist('course')
  more = request.args.get('more-courses', "").upper()
  courses.extend(
    (x if x.endswith('u') else x+'u'
    ) for x in re.findall(r'\w{4}\s*\d{4}u?', more))
  return render_template("_reschedule.html", semester=semester, courses=courses)

@app.route("/debug")
def page_debug():
  "shows the debug info"
  args = dict(request.args)
  return pformat(args)
